#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Point{
	int x;
	int y;
}point={0,0};
template<class Data>
class Stack{
private:
	Data* pData;
	Data* pDatadown;
	int size;
	int now;
public:
	Stack(int sizemax=100)
	{
		size=sizemax;
		pDatadown=(Data*)malloc(sizeof(Data)*size); 
		if(pDatadown==NULL)
			exit(0);
		pData=pDatadown;
		now=0;
	}
	~Stack()
	{
		free(pDatadown);
	}
	int pushData(Data data)
	{
		if(pData<pDatadown+size)
		{
			*pData=data;
			pData++;
			now++;
			return 0; 
		} 
		else
		{
			printf("\nwrong\n");
			return 1;
		 }	
	}
	int cleanStack()
	{
		pData=pDatadown;
		now=0;
		return 0;
	}
	Data pop()
	{
		Data data;
		if(pData>=pDatadown)
		{
			if(pData>pDatadown)
				pData--;
			data=*pData;
			if(now>0)
				now--;
			return data;
		} 
	}
	inline int show_now()
	{
		return now;
	}
	Data getTop()
	{
		return *pData;
	}
	bool findData(Data tempdata)
	{
		Data* ptemp=pData;
		while(ptemp!=pDatadown-1)
		{
			if(*ptemp==tempdata)
				return true;
			ptemp--;
		}
		return false;
	}
	bool is_empty()
	{
		if(now)
			return true;
		else
			return false;
	}
};
void printAll(int (*p)[8])
{
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			printf("%3d",p[i][j]);
			if(j==7)
				printf("\n");
		}
	}
}
bool DFS(int (*p)[8],int end,Point point,Point prePoint,int no,int me)
{
	if(p[point.x][point.y]==end)
		return true;
	p[point.x][point.y]=me;
	if(point.x+1<8&&p[point.x+1][point.y]!=no&&p[point.x+1][point.y]!=me)
	{
		struct Point temp=point;
		point.x++;
		if(DFS(p,end,point,temp,no,me))
			return true;
		else
			point=prePoint;
	}
	if(point.x-1>=0&&p[point.x-1][point.y]!=no&&p[point.x-1][point.y]!=me)
	{
		struct Point temp=point;
		point.x--;
		if(DFS(p,end,point,temp,no,me))
			return true;
		else
			point=prePoint;
	}
	if(point.y-1>=0&&p[point.x][point.y-1]!=no&&p[point.x][point.y-1]!=me)
	{
		struct Point temp=point;
		point.y--;
		if(DFS(p,end,point,temp,no,me))
			return true;
		else
			point=prePoint;
	}
	if(point.y+1<8&&p[point.x][point.y+1]!=no&&p[point.x][point.y+1]!=me)
	{
		struct Point temp=point;
		point.y++;
		if(DFS(p,end,point,temp,no,me))
			return true;
		else
			point=prePoint;
	}
	return false;
}
bool DFSstack(int (*p)[8],Point point,int end,int no,int me)
{
	Stack<Point> stack(64);
	Point first=point;
	if(p[point.x][point.y]==end)
		return true;
	p[point.x][point.y]=me;
	stack.pushData(point);
	while(1)
	{
		if(point.x+1<8&&p[point.x+1][point.y]!=no&&p[point.x+1][point.y]!=me)
		{
			point.x++;
			stack.pushData(point);
			if(p[point.x][point.y]==end)
				return true;
			p[point.x][point.y]=me;
		}
		else if(point.x-1>=0&&p[point.x-1][point.y]!=no&&p[point.x-1][point.y]!=me)
		{
			point.x--;
			stack.pushData(point);
			if(p[point.x][point.y]==end)
				return true;
			p[point.x][point.y]=me;
		}
		else if(point.y-1>=0&&p[point.x][point.y-1]!=no&&p[point.x][point.y-1]!=me)
		{
			point.y--;
			stack.pushData(point);
			if(p[point.x][point.y]==end)
				return true;
			p[point.x][point.y]=me;
		}
		else if(point.y+1<8&&p[point.x][point.y+1]!=no&&p[point.x][point.y+1]!=me)
		{
			point.y++;
			stack.pushData(point);
			if(p[point.x][point.y]==end)
				return true;
			p[point.x][point.y]=me;
		}
		else
		{
			point=stack.pop();
			if(point.x==first.x&&point.y==first.y)
			{
				int flag=1;
				if(point.x+1<8&&p[point.x+1][point.y]!=me&&p[point.x+1][point.y]!=no)
					flag=0;
				if(point.x-1>=0&&p[point.x-1][point.y]!=me&&p[point.x-1][point.y]!=no)
					flag=0;
				if(point.y+1<8&&p[point.x][point.y+1]!=me&&p[point.x][point.y+1]!=no)
					flag=0;
				if(point.y-1>=0&&p[point.x][point.y-1]!=me&&p[point.x][point.y-1]!=no)
					flag=0;
				if(flag)	
					return false;
				stack.pushData(point);
			}	
		}
	}
}
int main() 
{
	int p[8][8]=
	{
		{1,1,1,0,0,1,1,1,},
		{1,0,1,1,1,0,0,1,},
		{0,1,1,0,1,1,1,1,},
		{0,0,1,0,1,0,1,0,},
		{1,1,1,0,1,0,1,0,},
		{0,1,0,0,1,0,1,0,},
		{0,1,0,1,1,1,1,0,},
		{1,1,0,1,0,0,1,2,},
	};
	struct Point first={0,0};
	if(DFSstack(p,first,2,0,3))
		printf("yes\n");
	printAll(p);
	return 0;
}
